home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Various / DevDisk 65 (1989)(DevWare PD).zip / DevDisk 65 (1989)(DevWare PD).adf / mypixel / onepixel.s < prev    next >
Text File  |  1990-07-11  |  9KB  |  340 lines

  1. *  Program to draw a single pixel interposed on Single Playfield Code.
  2. *  Submitted by Thomas J. Eshelman, Reading, Pa.  11/25/88
  3. *
  4. *  Purpose:  Create a library routine to produces a single-playfield display
  5. *            using system graphics primitives.
  6. *
  7. *  Draw a pixel at predetermined location and color.
  8. *  This particular example is written for an early DevPak assembler.
  9. *  Please refer to accompanying Manx version for full comments.
  10.  
  11.    incdir   "fh0:Asm_Include/"
  12.  
  13.    include  exec/types.i
  14.    include  exec/exec_lib.i
  15.    include  graphics/gfx.i
  16.    include  graphics/gfxbase.i
  17.    include  graphics/rastport.i
  18.    include  graphics/view.i
  19.    include  graphics/graphics_lib.i
  20.    include  libraries/dosextens.i
  21.    include  libraries/dos_lib.i
  22.    include  workbench/workbench.i
  23.    include  workbench/startup.i
  24.    include  hardware/custom.i
  25.    include  tomesh.i
  26.  
  27.  
  28. NUMCOLS     EQU   8
  29. PLANEPTR    EQUR  d0
  30.  
  31. DEPTH       EQU   3                    Two sets of dimensions to remind that
  32. WIDTH       EQU   401                  the display is not the same as the
  33. HEIGHT      EQU   201                  bitmap.
  34.  
  35. VPWIDTH     EQU   321                  The odd value chosen to remind never
  36. VPHEIGHT    EQU   201                  to draw >= size of the bitmap.
  37.  
  38.  
  39.  
  40. start:
  41.  
  42.  
  43.    suba.l      a1,a1                   Asm. doesn't provide the automatic
  44.    CALLEXEC    FindTask                startup code of 'C'.  Hence, we steal
  45.    move.l      d0,mytask               this classic scheme from David Ashley.
  46.  
  47.    lea         gfxname(pc),a1
  48.    moveq       #0,d0
  49.    jsr         _LVOOpenLibrary(a6)
  50.    move.l      d0,GfxBase
  51.  
  52.    movea.l     d0,a1
  53.    move.l      gb_ActiView(a1),oldview
  54.  
  55.    lea         dosname(pc),a1
  56.    moveq       #0,d0
  57.    jsr         _LVOOpenLibrary(a6)
  58.    move.l      d0,DosBase
  59.  
  60.    clr.l       returnmsg
  61.  
  62.    movea.l     mytask(pc),a4
  63.    tst.l       pr_CLI(a4)
  64.    bne         nowb
  65.  
  66.    lea         pr_MsgPort(a4),a0
  67.    jsr         _LVOWaitPort(a6)        Must wait for WB to give a go-ahead.
  68.  
  69.    lea         pr_MsgPort(a4),a0
  70.    jsr         _LVOGetMsg(a6)          Received.  Get it off process port.
  71.  
  72.    move.l      d0,returnmsg            Save to reply with when closing.
  73.  
  74.    movea.l     d0,a4
  75.    move.l      sm_ArgList(a4),d0       (This won't happen.  Is used as for
  76.    beq         nowb                           convenience only.)
  77.  
  78.    move.l      d0,a4
  79.    move.l      wa_Lock(a4),d1
  80.  
  81.    movea.l     DosBase(pc),a6
  82.    CALLDOS     CurrentDir
  83.  
  84. nowb:
  85.  
  86.    bsr         playfields              NOW YOU MAY CALL THE PROGRAM PROPER
  87.  
  88.    move.w      #160,d0
  89.    move.w      #100,d1
  90.    move.w      #3,d2
  91.  
  92.    bsr         paint_pixel             Draw un pixel.
  93.  
  94.    move.l      #500,d1
  95.    CALLDOS     Delay
  96.  
  97. closeall:
  98.  
  99.    move.l      returnmsg(pc),d4        To quit, we must retrieve the message.
  100.    beq         nowb2                   If none, we  came from the CLI.
  101.  
  102.    CALLEXEC    Forbid                  May not multitask during the reply.
  103.  
  104.    move.l      d4,a1
  105.    jsr         _LVOReplyMsg(a6)        Reply to the WorkBench!
  106.  
  107. nowb2:
  108.  
  109.    lea         bitmap+bm_Planes(pc),a2 Deallocate raster memory.
  110.    moveq       #DEPTH-1,d2
  111.  
  112. deallocate_1:
  113.   
  114.    move.l      #WIDTH,d0
  115.    move.l      #HEIGHT,d1
  116.    movea.l     (a2),a0                 Remember to dereference.
  117.    move.l      a0,d2
  118.    beq         quit_0
  119.  
  120.    CALLGRAF    FreeRaster
  121.  
  122.    adda.l      #4,a2
  123.    dbra        d2,deallocate_1
  124.  
  125. quit_0:
  126.  
  127.    movea.l     cm(pc),a0
  128.    move.l      a0,d0
  129.    beq         quit_1
  130.    CALLGRAF    FreeColorMap
  131.  
  132. quit_1:
  133.  
  134.    lea         vport(pc),a0
  135.    move.l      a0,d2
  136.    beq         quit_2
  137.    CALLGRAF    FreeVPortCopLists
  138.  
  139. quit_2:
  140.  
  141.    lea         view(pc),a0
  142.    movea.l     v_LOFCprList(a0),a0
  143.    move.l      a0,d2
  144.    beq         quit_3
  145.    CALLGRAF    FreeCprList
  146.  
  147. quit_3:
  148.  
  149.    movea.l     oldview(pc),a1
  150.    move.l      a1,d2
  151.    beq         quit_4
  152.    CALLGRAF    LoadView
  153.  
  154. quit_4:
  155.  
  156.    movea.l     DosBase(pc),a1
  157.    move.l      a1,d2
  158.    beq         quit_5
  159.    CALLEXEC    CloseLibrary
  160.  
  161. quit_5:
  162.  
  163.    movea.l     GfxBase(pc),a1
  164.    move.l      a1,d2
  165.    beq         quit_6
  166.    CALLEXEC    CloseLibrary
  167.  
  168. quit_6:
  169.  
  170.    rts                                 Return to system.
  171.  
  172.  
  173.  
  174. playfields:
  175.  
  176.    lea         view(pc),a1
  177.    CALLGRAF    InitView
  178.  
  179.    lea         view(pc),a1
  180.    move.l      #vport,v_ViewPort(a1)
  181.  
  182.    lea         vport(pc),a0
  183.    jsr         _LVOInitVPort(a6)
  184.  
  185.    moveq       #NUMCOLS,d0
  186.    jsr         _LVOGetColorMap(a6)     Declares/allocates a struct ColorMap
  187.    move.l      d0,cm                   invisibly, and returns pointer to it.
  188.  
  189.    lea         vport(pc),a0
  190.    move.l      d0,vp_ColorMap(a0)
  191.    move.w      #VPWIDTH,vp_DWidth(a0)
  192.    move.w      #VPHEIGHT,vp_DHeight(a0)
  193.  
  194.    move.l      #rasinfo,vp_RasInfo(a0)
  195.    move.w      #0,vp_Modes(a0)
  196.  
  197.    lea         vport(pc),a0
  198.    lea         colortable(pc),a1
  199.    moveq       #NUMCOLS,d0
  200.    jsr         _LVOLoadRGB4(a6)        Loads the struct ColorMap, supra.
  201.  
  202.    lea         bitmap(pc),a0
  203.    move.l      #DEPTH,d0
  204.    move.l      #WIDTH,d1
  205.    move.l      #HEIGHT,d2
  206.    jsr         _LVOInitBitMap(a6)
  207.  
  208. allocate:
  209.  
  210.    lea         bitmap+bm_Planes(pc),a2
  211.    moveq       #DEPTH-1,d2
  212.  
  213. plane:
  214.  
  215.    move.l      #WIDTH,d0
  216.    move.l      #HEIGHT,d1
  217.    jsr         _LVOAllocRaster(a6)
  218.    move.l      PLANEPTR,(a2)
  219.    beq         closeall
  220.  
  221.    movea.l     PLANEPTR,a1
  222.    RASSIZE     #WIDTH,#HEIGHT          Macro returns in d0.
  223.    moveq       #0,d1
  224.    jsr         _LVOBltClear(a6)
  225.  
  226.    adda.l      #4,a2
  227.    dbra        d2,plane
  228.  
  229.    lea         rasinfo(pc),a0
  230.    move.l      #bitmap,ri_BitMap(a0)
  231.    move.w      #0,ri_RxOffset(a0)
  232.    move.w      #0,ri_RyOffset(a0)
  233.    move.l      #0,ri_Next(a0)
  234.  
  235.    lea         view(pc),a0
  236.    lea         vport(pc),a1
  237.    jsr         _LVOMakeVPort(a6)
  238.  
  239.    lea         view(pc),a1
  240.    jsr         _LVOMrgCop(a6)
  241.  
  242.    lea         rastport(pc),a1
  243.    jsr         _LVOInitRastPort(a6)
  244.  
  245.    lea         rastport(pc),a1
  246.    move.l      #bitmap,rp_BitMap(a1)
  247.  
  248.    lea         rastport(pc),a1
  249.    moveq       #0,d0
  250.    jsr         _LVOSetRast(a6)
  251.  
  252.    lea         view(pc),a1
  253.    jsr         _LVOLoadView(a6)
  254.  
  255.    rts
  256.  
  257.  
  258. paint_pixel:
  259.  
  260. *  For my purposes, I will place x in d0, y in d1 and color in d2 prior to
  261. *  calling the routine.  See the Manx code accompanying this file for full
  262. *  commentary.
  263.  
  264.    lea      $dff000,a0
  265.    lea      bitmap,a2
  266.  
  267.    move.w   d2,d3                      Copy color.
  268.    move.w   d1,d7                      Copy Y coordinate.
  269.    mulu     bm_BytesPerRow(a2),d7      Byte offset of line containing Y.
  270.  
  271.    move.w   d0,d4                      Copy X coordinate.
  272.    lsr.w    #4,d4
  273.    lsl.w    #1,d4                      Divide by 8 while clearing bit 0.
  274.    add.w    d4,d7                      Add X byte offset to Y offset.
  275.    ext.l    d7
  276.  
  277.    move.w   d0,d4                      Copy X coordinate.
  278.    andi.w   #$f,d4                     Retrieve bit additional.
  279.  
  280.    move.w   #$8000,d5                  Set bit representing byte's 'base'.
  281.    lsr.w    d4,d5                      Move right to precise draw position.
  282.    move.w   d5,d6                      Mask to OR a one for color draw.
  283.    not.w    d6                         Mask to AND a zero for Bg color erase.
  284.  
  285.    move.b   bm_Depth(a2),d0            Number of planes to draw into.
  286.    ext.w    d0
  287.    subq.w   #1,d0                      Subtract one for dbra.
  288.  
  289.    clr.w    d1                         Begin counter at 0.  Increment below.
  290.  
  291. pixl61:
  292.  
  293.    move.w   d1,d2                      Place the 0 to whatever.
  294.    lsl.w    #2,d2                      Multiply * 4 to increment plane ptr.
  295.    movea.l  bm_Planes(a2,d2.w),a3      Retrieve this plane pointer.
  296.  
  297.    add.l    d7,a3                      Come to our pixel.
  298.    btst     d1,d3                      Test the color bit in our plane.
  299.    beq      pixl62                     Branch if unset.
  300.  
  301.    or.w     d5,(a3)                    Make sure the bit in the 'as shifted'
  302. *                                      position is set to cause the draw.
  303.    bra      pixl63                     Test next plane.
  304.  
  305. pixl62:
  306.  
  307.    and.w    d6,(a3)                    Make sure the bit in the 'as shifted'
  308. *                                      position is NOT set to cause an erase.
  309.  
  310. pixl63:
  311.  
  312.    addq.w   #1,d1                      Advance to next plane, and to the
  313.    dbra     d0,pixl61                  corresponding bit in the binary color
  314. *                                      number.
  315.    rts
  316.  
  317.  
  318.  
  319.  
  320. gfxname:       GRAFNAME
  321. dosname:       DOSNAME
  322. colortable:    dc.w  $000,$fff,$f00,$0f0,$00f,$ff0,$0ff,$f0f
  323.  
  324. GfxBase:       ds.l   1
  325. DosBase:       ds.l   1
  326. mytask:        ds.l   1
  327. returnmsg:     ds.l   1
  328. cm:            ds.l   1
  329. oldview:       ds.l   1
  330. view:          ds.b   v_SIZEOF
  331. vport:         ds.b   vp_SIZEOF
  332. bitmap:        ds.b   bm_SIZEOF
  333. rastport:      ds.b   rp_SIZEOF
  334. rasinfo:       ds.b   ri_SIZEOF
  335. fillcolor:     ds.w   1
  336.  
  337.                            end
  338.  
  339.  
  340.